package com.akk.platform.manage.business;

import com.akk.common.enums.APPEnums;
import com.akk.module.app.entity.App;
import com.akk.module.app.service.AppService;
import com.akk.utils.PageUtils;
import com.akk.utils.Query;
import com.akk.utils.RestResponse;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AppBusiness {
    @Autowired
    AppService appService;

    public RestResponse appList(Query query) {
        PageHelper.startPage(query.getPage(),query.getLimit());
        List<App> apps = appService.findByParam(query.getSearch());
        return RestResponse.build(PageUtils.buildPage(apps,(int) new PageInfo<>(apps).getTotal(),query));
    }

    public RestResponse appUpdate(App app) {
        app.setUpdateDate(new Date());
        appService.update(app);
        return RestResponse.build("操作成功");
    }

    public RestResponse appAdd(App app) {
        app.setCreateDate(new Date());
        app.setUpdateDate(new Date());
        app.setAppStatus(APPEnums.StatusEnum.NORMAL.getValue());
        appService.save(app);
        return RestResponse.build("操作成功");
    }


    public RestResponse selectAppList() {
        List<App> apps = appService.findByStatus(APPEnums.StatusEnum.NORMAL.getValue());
    return RestResponse.build(apps);
    }
}
